package com.example.zhifubao;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;


import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Properties;

@Slf4j
public class PropertiesUtil {

    private   Properties properties;



    private  PropertiesUtil(String fileName){
        properties = new Properties();

        try {
            properties.load(new InputStreamReader(PropertiesUtil.class.getClassLoader().getResourceAsStream(fileName),"utf-8"));

        } catch (IOException e) {
            log.info("配置文件读取异常");
        }


    }



    public  static PropertiesUtil load(String fileName){




        return   new PropertiesUtil(fileName);
    }




    public  String getProperty(String key){
        String  value = properties.getProperty(key.trim());

        if(StringUtils.isBlank(value)) {
            return null;
        }
        return  value.trim();
    }


    public  String getProperty(String key,String defaultValue){
        String  value = properties.getProperty(key.trim());

        if(StringUtils.isBlank(value)) {
            value = defaultValue;
        }
        return  value.trim();
    }


}
